package database

import (
	"fmt"
	"gorm.io/driver/mysql"
	"gorm.io/gorm"
	"petCombo-srv/global"
	"petCombo-srv/internal/model"
)

var err error

func Mysql() {
	// 参考 https://github.com/go-sql-driver/mysql#dsn-data-source-name 获取详情

	MysqlConfig := global.Config.Mysql

	dsn := fmt.Sprintf("%s:%s@tcp(%s:%s)/%s?charset=utf8mb4&parseTime=True&loc=Local",
		MysqlConfig.User,
		MysqlConfig.Password,
		MysqlConfig.Host,
		MysqlConfig.Port,
		MysqlConfig.Database)
	global.DB, err = gorm.Open(mysql.Open(dsn))
	global.DB.AutoMigrate(&model.Combo{}, &model.Pets{}, &model.Address{})
}
